import os
from mon_daemon_utils import decode

DEFAULT_CONF = os.path.dirname(os.path.abspath(__file__)) + os.path.sep + 'daemon_default_config'

def load_config(config_file):
    try:
        fp = open(config_file)
    except IOError, e:
        if e.errno != 2:
            raise e
        else:
            raise MonDaemonException, 'config file not found!'
    else:
        configstring = fp.read()
        config = decode(configstring)
        fp.close()
        return config

global_config = load_config(DEFAULT_CONF)
